package cn.com.cloudpioneer.evaluate.controller;

import cn.com.cloudpioneer.evaluate.model.UserModel;
import cn.com.cloudpioneer.evaluate.service.UserService;
import cn.com.cloudpioneer.evaluate.utils.CustomException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther maruikai
 * @create 2023/9/13-17:24
 */
@RestController
@RequestMapping("/api/xgs/user")
@Api(tags = "用户管理")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/set", method = RequestMethod.POST)
    @ApiOperation(value = "注册用户")
    public Object setUser(@RequestParam(value = "userName", defaultValue = "") String userName,
                          @RequestParam String loginName,
                          @RequestParam String roleIds) throws CustomException {
        return userService.setUser(userName, loginName, roleIds);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(value = "登录")
    public Object login(@RequestParam String loginName,
                        @RequestParam String password) throws CustomException {
        return userService.loginUser(loginName, password);
    }

    @RequestMapping(value = "/update_pwd", method = RequestMethod.POST)
    @ApiOperation(value = "修改密码")
    public Object updatePassword(@RequestBody UserModel userModel) throws CustomException {
        return userService.updatePassword(userModel);
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    @ApiOperation(value = "用户列表", response = UserModel.class)
    public Object getUserList(@RequestParam(value = "keyword", defaultValue = "") String keyword,
                              @RequestParam("pageNo") int pageNo,
                              @RequestParam("pageSize") int pageSize) {
        return userService.getUserList(keyword, pageNo, pageSize);
    }


    @RequestMapping(value = "appraiser_list", method = RequestMethod.GET)
    @ApiOperation(value = "用户列表")
    public Object getAppraiserUserList() {
        return userService.getAppraiserUserList();
    }

    @RequestMapping(value = "/update_role", method = RequestMethod.POST)
    @ApiOperation(value = "编辑权限")
    public Object updateUserRole(@RequestBody UserModel userModel) throws CustomException {
        return userService.updateUserRole(userModel);
    }

    @RequestMapping(value = "/role_list", method = RequestMethod.POST)
    @ApiOperation(value = "权限列表")
    public Object roleList() throws CustomException {
        return userService.roleList();
    }


    @RequestMapping(value = "/del", method = RequestMethod.GET)
    @ApiOperation(value = "删除用户")
    public Object delUser(@RequestParam String userId) throws CustomException {
        return userService.delUser(userId);
    }


}
